<template>
  <div class="app-container">
    <div class="qrCodeContainer" style="width: 450px; height: 50px; display: none; width: 100%">
      <h1 class="title" style="width: 480px; margin-left: 45%; font-size: 17px">{{ $t(`Print.PurchaseInboundList`) }}</h1>
      <div style="width: 95%; margin: auto">
        <div style="display: flex; width: 100%; font-size: 13px; justify-content: space-between">
          <h2 style="font-size: 13px; font-size: 11px">{{ $t(`Print.Manufacturers`) }}:{{ slipNoList3[0]?.vendorName }}</h2>
          <h2 style="margin-left: 50px; font-size: 13px; font-size: 11px">{{ $t(`Print.ArrivalDate`) }}:{{ slipNoList3[0]?.sendDate }}</h2>
          <h2 style="margin-left: 50px; font-size: 13px; font-size: 11px">{{ $t(`Print.InboundOrderNumber`) }}:{{ slipNoList3[0]?.recNo }}</h2>
          <h2 style="margin-left: 50px; font-size: 13px; font-size: 11px">{{ $t(`Print.DeliveryNoteNumber`) }}:{{ slipNoList3[0]?.sendNo }}</h2>
          <h2 style="margin-left: 50px; font-size: 13px; font-size: 11px">{{ $t(`Print.DateOfPrinting`) }}:{{ formatCurrentDateTime(currentDate) }}</h2>
        </div>

        <div style="width: 100%">
          <table style="width: 100%; font-size: 13px">
            <thead>
              <tr>
                <th>{{ $t(`Print.Directives`) }}</th>
                <th>{{ $t(`Print.MaterialColorKey`) }}</th>
                <th>{{ $t(`Print.MaterialName`) }}</th>
                <th>{{ $t(`Print.Specification`) }}</th>
                <th>{{ $t(`Print.Unit`) }}</th>
                <th>{{ $t(`Print.Type`) }}</th>
                <th>{{ $t(`Print.TActualAmountReceivedype`) }}</th>
                <th>{{ $t(`Print.Remark`) }}</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(iten1, index) in slipNoList3" :key="index">
                <td>{{ iten1.lotDetail }}</td>

                <td>{{ iten1.mtlColor }}</td>
                <td>{{ iten1.mtlName }}</td>
                <td>{{ iten1.mtlSpec }}</td>
                <td>{{ iten1.mtlUnit }}</td>

                <td>{{ iten1.slipType }}</td>
                <td>{{ iten1.sendQty }}</td>

                <td>{{ iten1.remark }}</td>
                <!-- 更多的数据单元格 -->
              </tr>
              <!-- 更多的行 -->
            </tbody>
            <!-- 可选的 tfoot 部分 -->
          </table>

          <!-- <Table :tableHeader="tableHeader5" :tableData="slipNoList" /> -->
        </div>
        <h3 style="margin-left: 650px; font-size: 7px !important">{{ $t(`Print.TotalDispatch`) }}:{{ numberList }}</h3>
        <div style="padding: 0; margin: 0; font-size: 11px; line-height: normal; font-weight: normal; font-family: inherit; color: inherit">
          <h3 style="margin: 0; padding: 0; font-size: 7px !important">{{ $t(`Print.Illustrate`) }}</h3>
          <h3 style="margin: 0; padding: 0; font-size: 7px !important">
            {{ $t(`Print.WhenDeliveringYouMustBringTheDeliveryNoteToThePlaceToPrintTheWarehousingOrderTheGoodsArriveAtTheOrderIfYouDoNotBringTheOrderWillBeDelayedThankYouForYourCooperation`) }}
          </h3>
          <h3 style="margin: 0; padding: 0; font-size: 7px !important">
            {{ $t(`Print.TheSupplyOrderMustContainInstructionSheetMaterialColorMaterialNameSpecificationQuantityUnitUnitPriceAmountIncludingTaxOrExclusiveDeliveryPeriod`) }}
          </h3>
          <h3 style="margin: 0; padding: 0; font-size: 7px !important">{{ $t(`Print.AccordingToTheConfirmedSamplesAndTestResultsWeAreWillingToAcceptTheBuyersReturnOrDiscountWhenTheQualityIsPoor`) }}</h3>
          <h3 style="margin: 0; padding: 0; font-size: 7px !important">
            {{ $t(`Print.PleaseDliverTheGoodsDuringWorkingHoursWillNotReceiveTheGoodsDuringTheOffdutyHoursIfThereAreSpecialCircumstancesPleaseContactThePurchasingDepartmentOfTheSupplyCenterTankYou`) }}
          </h3>
          <h3 style="margin: 0; padding: 0; font-size: 7px !important">
            {{ $t(`Print.IfTheDeliveryIsDelayed005OfTheTotalOrderPriceIsUsedAsLiquidatedDamagesAndTheSupplierShallBearAllTheLossesCausedByTheDeliveryTimeAndPoorQuality`) }}
          </h3>
          <h3 style="margin: 0; padding: 0; font-size: 7px !important">TEL:18296370303</h3>
        </div>

        <div style="display: flex; justify-content: space-between; width: 85%; font-size: 17px; width: 80%; margin: auto">
          <h2 style="font-size: 13px">{{ $t(`Print.Attn`) }}:</h2>
          <h2 style="font-size: 13px">{{ $t(`Print.Reviewers`) }}:</h2>
          <h2 style="font-size: 13px">{{ $t(`Print.Manufacturers`) }}:</h2>
          <h2 style="font-size: 13px">{{ $t(`Print.ReceiptInspector`) }}:</h2>
        </div>
      </div>
    </div>

    <div class="ProductionDynamic">
      <!-- 头部 -->
      <div class="ProductionDynamicHeader">
        <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
      </div>

      <!-- 主体 -->
      <el-card class="mt10" shadow="always" :body-style="{ padding: '0' }">
        <el-card shadow="never" :body-style="{ padding: '5px 10px' }">
          <div slot="header" class="f16">
            <span style="font-weight: 600">{{ $t(`Print.InquireAboutTheWarehousingDetails`) }}</span>
          </div>
          <Table
            :tableHeader="tableHeader"
            :tableData="tableData"
            class="mt10"
            :TableHeight="75"
            :outTableHeight="120"
            :summaryData="summaryData"
            summary
            @currentRow="currentRow"
          />
        </el-card>
        <el-card shadow="never" :body-style="{ padding: '5px 10px 10px' }">
          <div slot="header" class="f16">
            <span style="font-weight: 600">{{ $t(`Print.InstructionDetails`) }}</span>
          </div>
          <Table
            :summaryData="summaryData2"
            summary
            :tableHeader="tableHeader2"
            :tableData="tableData2"
            class="mt10"
            :TableHeight="25"
            :outTableHeight="120"
          />
          <PageModule :PageData="{ total }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
        </el-card>
      </el-card>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref, watch } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'MaterialWarehousingQuery'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import Find from '@/components/Find/index.vue'
import { selectList, selectSomeList } from '@/plugins/mixin'
import fileRequest from '@/utils/fileRequest'
import service from '@/utils/request'
import { ElMessage } from 'element-plus'
import { debounce } from 'lodash'
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入订购单号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入送货单号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料颜色',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料名称',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入物料编码',
    inputValue: ''
  },
  {
    type: 'date',
    dateLabel: '入仓日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入入库单号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入退货单号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入送货单号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商代码 厂商名称',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'date',
    dateLabel: '退货日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出'
  },
  {
    type: 'button',
    checkboxLabel: '打印入库单'
  }
]) as any
const tableHeader = ref([
  {
    label: '指令',
    prop: 'lotDetail'
  },
  {
    label: '订购单号',
    prop: 'purNo',
    width: '71px'
  },
  {
    label: '入仓日期',
    prop: 'recDate'
  },
  {
    label: '物料编码',
    prop: 'mtlNo',
    width: 120
  },
  {
    label: '厂商名称',
    prop: 'vendorName',
    width: '71px'
  },
  {
    label: '型体',
    prop: 'purStyle',
    width: '71px'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor',
    width: '71px'
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    width: '120px'
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    width: '73px'
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    width: '73px'
  },{
    label: '单价',
    prop: 'price',
    width: '73px'
  },
  {
    label: '送货数量',
    prop: 'sendQty',
    width: '73px'
  },
  {
    label: '退货数量',
    prop: 'returnQty',
    width: '73px'
  },
  {
    label: '暂收数量',
    prop: 'acceptQty',
    width: '73px'
  },
  {
    label: '合格数量',
    prop: 'okQty',
    width: '73px'
  },
  {
    label: '入库单号',
    prop: 'recNo',
    width: '100px'
  },
  {
    label: '公斤数',
    prop: 'kgQty',
    width: '71px'
  },
  {
    label: '类型',
    prop: 'slipType',
    width: '71px'
  },
  {
    label: '仓管员',
    prop: 'sysUser',
    width: '71px'
  },
  {
    label: '单据检核',
    width: '71px',
    type: 'checkbox',
    prop: 'cfmFlag'
  },
  {
    label: '单价检核',
    type: 'checkbox',
    prop: 'financeCfmFlag'
  },
  {
    label: '对账检核',
    width: '71px',
    type: 'checkbox',
    prop: 'reconciliation'
  },
  {
    label: '外观合格否',
    prop: 'acheckFlag'
  },
  {
    label: '外观不良原因',
    prop: 'areason'
  },
  {
    label: '物性合格否',
    prop: 'pcheckFlag'
  },
  {
    label: '物性不良原因',
    prop: 'preason'
  },

  {
    label: '备注',
    prop: 'remark'
  },
  {
    label: '退货日期',
    prop: 'returnDate'
  },
  {
    label: '退货单号',
    prop: 'returnNo'
  }
])

// 表一模块
// '置空'按钮
const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
    getTableList()
  }
  if (content === '导出') {
    const res = (await fileRequest.post(`/material/exportMaterial`, {
      lotNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
      )?.inputValue,
      mtlColor: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料颜色'
      )?.inputValue,
      mtlName: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料名称'
      )?.inputValue,
      mtlNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入物料编码'
      )?.inputValue,
      purNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入订购单号'
      )?.inputValue,
      recDateEnd: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入仓日期'
      )?.dateValue?.[1],
      recDateStart: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入仓日期'
      )?.dateValue?.[0],
      recNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入入库单号'
      )?.inputValue,
      returnDateEnd: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '退货日期'
      )?.dateValue?.[1],
      returnDateStart: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '退货日期'
      )?.dateValue?.[0],
      returnNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入退货单号'
      )?.inputValue,
      sendNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入送货单号'
      )?.inputValue,
      typeNo: formList.value
        .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '分类')
        ?.selectValue?.split(' ')[0],
      style: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
      )?.inputValue,
      vendorName: formList.value
        .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
        ?.selectValue?.split(' ')[1],
      vendorNo: formList.value
        .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
        ?.selectValue?.split(' ')[0],
      pageNum: currentPage.value,
      pageSize: pageSize.value
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`filename=`)[1])
    link.download = FileName //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
  if (content === '打印入库单') {
    if (slipNoList3.value.length === 0) {
      JMessage.warning('请点击需要打印的数据')
    } else if (slipNoList3.value[0].recNo === null) {
      JMessage.warning('请选择有入库单号的进行打印')
    } else {
      if (currentTableRow.value.recNo)
        formList.value.find(
          (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入入库单号'
        ).inputValue = currentTableRow.value.recNo
      setTimeout(() => {
        printQRCode()
      }, 3000)
    }
  }
}

const printQRCode = () => {
  const qrCodeContainer = document.querySelector<any>('.qrCodeContainer')
  if (qrCodeContainer) {
    // 临时显示 .qrCodeContainer 以获取其内容
    qrCodeContainer.style.display = 'block'

    const printWindow = window.open('', '_blank')
    printWindow!.document.write(`
      <!DOCTYPE html>
      <html>
        <head>
          <title>打印指令领料作业</title>
          <link rel="stylesheet" type="text/css" href="print.css" media="print">
          <style>
            body, html {
              margin: 0;
              padding: 0;
            }
            @page {
              size: auto; 
              margin: 3mm;
            }
            @media print {
                /* 打印时的样式 */
             
                
                /* 其他打印样式 */
            }
            h2 {
                    margin-left: initial; /* 或者设置适合打印的左边距 */
                    page-break-inside: avoid; /* 避免在h2元素内部分页 */
                }
            h3{
              font-size:13px;
            }
               

            table, th, td {
                    border: 1px solid black; 
                    border-collapse: collapse; 
                    text-align: center;
                  }
                  th, td {
                    padding: 5px; /* 设置内边距 */
                    text-align: left; /* 设置文本对齐方式 */
                    text-align: center;
                    font-size:11px
                  }
                  .double-line {
                    border-top: 2px dashed red; 
                    border-bottom: 2px dashed red; 
                    text-align: center;
                  }
           
            /* 可以在这里添加更多自定义的打印样式 */
          </style>
        </head>
        <body>
    `)

    // 将 .qrCodeContainer 的内容复制到打印窗口的 body 中
    const cloneContainer = qrCodeContainer.cloneNode(true)
    printWindow!.document.body.appendChild(cloneContainer)

    printWindow!.document.write(`
        </body>
      </html>
    `)
    printWindow!.document.close()

    // 开始打印
    printWindow!.print()

    // 打印完成后，可以恢复 .qrCodeContainer 的原始显示状态
    qrCodeContainer.style.display = 'none'
  }
}
const currentDate = ref(new Date())
// 日期
const formatCurrentDateTime = (date?: Date) => {
  const year = date!.getFullYear()
  const month = String(date!.getMonth() + 1).padStart(2, '0') // 使用padStart确保月份是两位数
  const day = String(date!.getDate()).padStart(2, '0') // 使用padStart确保日期是两位数
  const hours = String(date!.getHours()).padStart(2, '0') // 小时
  const minutes = String(date!.getMinutes()).padStart(2, '0') // 分钟
  const seconds = String(date!.getSeconds()).padStart(2, '0') // 秒

  // 返回格式化的日期时间字符串
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}

const tableData = ref([])
const isLoading = ref(true)
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 9,
    num: 0
  },
  {
    index: 10,
    num: 0
  },
  {
    index: 11,
    num: 0
  },
  {
    index: 12,
    num: 0
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
// 获取表数据
const getTableList = debounce(async () => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/material/getInventoryDetail', {
    lotNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
    )?.inputValue,
    mtlColor: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料颜色'
    )?.inputValue,
    mtlName: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料名称'
    )?.inputValue,
    mtlNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入物料编码'
    )?.inputValue,
    purNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入订购单号'
    )?.inputValue,
    recDateEnd: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入仓日期'
    )?.dateValue?.[1],
    recDateStart: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入仓日期'
    )?.dateValue?.[0],
    recNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入入库单号'
    )?.inputValue,
    returnDateEnd: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '退货日期'
    )?.dateValue?.[1],
    returnDateStart: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '退货日期'
    )?.dateValue?.[0],
    returnNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入退货单号'
    )?.inputValue,
    sendNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入送货单号'
    )?.inputValue,
    typeNo: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '分类')
      ?.selectValue?.split(' ')[0],
    style: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
    )?.inputValue,
    vendorName: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
      ?.selectValue?.split(' ')[1],
    vendorNo: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
      ?.selectValue?.split(' ')[0],
    pageNum: currentPage.value,
    pageSize: pageSize.value
  })
  isLoading.value = false
  tableData.value = tableDataList.inventoryDetails.map((item: any) => {
    item.cfmFlag === 'Y' ? (item.cfmFlag = true) : (item.cfmFlag = false)
    item.financeCfmFlag === 'Y' ? (item.financeCfmFlag = true) : (item.financeCfmFlag = false)
    item.reconciliation === 'Y' ? (item.reconciliation = true) : (item.reconciliation = false)
    return item
  })
  total.value = tableDataList.total
  currentRow()
  summaryData.value[0].num = tableDataList.detailsCount.sendQtyCount
  summaryData.value[1].num = tableDataList.detailsCount.returnQtyCount
  summaryData.value[2].num = tableDataList.detailsCount.acceptQtyCount
  summaryData.value[3].num = tableDataList.detailsCount.okQtyCount
}, 500)
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)
const getSelectList = async () => {
  await selectList(formList, () => service.get('/MaterialOrder/getOrderCondition'))
  const type = formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '分类') as any
  const res = await service.get<any, any>('/back/getMtlType3')
  res.forEach((Vendor: any) => {
    type.selectOptions.push({
      optionLabel: Vendor.typeName,
      optionValue: `${Vendor.typeNo}  ${Vendor.typeName}`,
      LeftLabel: `${Vendor.typeNo}`,
      RightLabel: `${Vendor.typeName}`
    })
  })
}
onMounted(() => {
  getSelectList()
})

// 底部表格数据
const tableData2 = ref([])

const tableHeader2 = ref([
  {
    label: '指令',
    prop: 'lotDetail'
  },
  {
    label: '请购数量',
    prop: 'qty'
  },
  {
    label: '已收数量',
    prop: 'recQty'
  },
  {
    label: '未收数量',
    prop: 'unRecQty'
  }
])
const summaryData2 = ref<summaryDataType[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  },
  {
    index: 3,
    num: 0
  }
])
const slipNoList3 = ref<any>([])
const numberList = ref(0)
const currentTableRow = ref({}) as any
// 点击表给另一张表传数据
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}) => {
  currentTableRow.value = row
  slipNoList3.value = tableData.value.filter((item: any) => row.recNo === item.recNo)
  // 假设 numberList 是一个变量，想要保存总和
  numberList.value = slipNoList3.value.reduce((accumulator: any, current: any) => {
    return accumulator + (current.sendQty || 0) // Ensure sendQty is treated correctly
  }, 0)

  let { lotDetail, purNo, mtlNo }: any = row
  // 给表二传指令号
  let table2Data = await service.post<any, any>(`/material/getLotDetail`, {
    lotDetail,
    purNo,
    mtlNo
  })
  if (table2Data.count) {
    tableData2.value = table2Data.lotDetailList
    summaryData2.value[0].num = table2Data.count.qtyCount
    summaryData2.value[1].num = table2Data.count.recQtyCount
    summaryData2.value[2].num = table2Data.count.unRecQtyCount
  }
}
</script>

<style lang="less" scoped>
// 主体样式
.ProductionDynamicMain {
  width: 100%;
  height: 670px;
  margin-top: 20px;

  .ProductionDynamicMainCard {
    width: 100%;
    height: 100%;
    box-shadow: none;
  }
}

// 主体头
.ProductionDynamicMainCardHeader {
  width: 98%;
  margin: auto;
  margin-top: 10px;
  margin-bottom: 10px;
}

.MainLeftCardH1 {
  font-size: 16px;
}

.ProductionDynamicMainCardBottomRightBottom {
  width: 100%;
  height: 150px;
  display: flex;

  .ProductionDynamicMainCardBottomRightBottomLeft {
    width: 50%;
    height: 100%;
    display: flex;
    margin-top: 45px;
  }

  .ProductionDynamicMainCardBottomRightBottomRight {
    width: 50%;
    height: 100%;
    display: flex;
    justify-content: right;
    margin-top: 120px;
  }
}

// input输入框的样式
.timelineMainInput {
  width: 73px;
  height: 25px;
}

.timelineMainH1 {
  width: 73px;
  text-align: center;
}

// 按钮样式
.ProductionDynamicMainCardBottomRightBottomLeftBtn {
  background-color: #f89027;
  margin: 15px 15px 0 15px;
}

.bg {
  background-color: #e7e7e7;
  border: 1px solid #e7e7e7;
  color: #000000;
}
</style>
